#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int count = 0;

void bubble_sort(int arr[], int sz)
{
	int temp = 0;
	int i = 0;
	int j = 0;
	int flag = 1;

	for (i = 0; i < sz - 1; i++)
	{
		for (j = 0; j < sz - 1 - i; j++)
		{
			count++;
			if (arr[j] > arr[j + 1])
			{
				temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;
				flag = 0;
			}
		}
		if (flag == 1)
		{
			break;
		}
	}
	printf("%d\n", count);
}

void print(int arr[], int sz)
{
	for (int i = 0; i < sz; i++)
	{
		printf("%d  ", arr[i]);
	}
	printf("\n");
}

int main()
{
	int arr[10] = { 9,8,7,6,5,4,3,2,1,0 };

	int sz = sizeof(arr) / sizeof(arr[0]);
	print(arr, sz);

	bubble_sort(arr, sz);
	print(arr, sz);
	
	return 0;
}

